// 云函数入口文件
const cloud = require('qq-server-sdk');
var request = require('request-promise');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {

  const {
    OPENID,
    APPID,
    ENV
  } = cloud.getQQContext()

  return new Promise((resolve, reject) => {
    request({
      url: 'http://192.144.227.111:8000/api/token/',
      method: "Post",
      // headers: {
      //   "content-Type": "application/x-www-form-urlencoded"
      // },
      form: {"username":'zhaolin', "password":"zhao123456"}
    }, function (error, response, body) {
      console.log(error, response, body)
      resolve(response)
      reject(error)
      // var body_json = JSON.parse(body)
      // aid = body_json.results.mocPaperDto.aid
      // if (!aid) {
      //   reject('aid获取失败')
      // }
    })
  })

  return {
    OPENID,
    APPID,
    ENV
  }
}
